package br.com.orion.sga.controller;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateController {

	
	
	/**
	 * Method that will called to convert a date 
	 * in any format to the format informed on
	 * the format parameter
	 * @param date
	 * @param format
	 * @return Date formated
	 */
	public static Date convertToDate(Date date, String format){
		
		SimpleDateFormat dateFormat = new SimpleDateFormat(format);
		SimpleDateFormat formatEUA = new SimpleDateFormat("dd/MM/yyyy");
		
		Date dateConverted = null;
		
		if (date != null) {
			
			String strDate = formatEUA.format(date.getTime());

			// TODO corrigir isso usar o objeto Calendar ou outro qualquer para
			// retornar a data no formato necessário
			try {
				dateConverted = dateFormat.parse(strDate);
			} catch (ParseException e) {

				e.printStackTrace();
			}
		}
		
		return dateConverted;
	}
	
	
}
